#!/usr/bin/python3
# -*- coding:utf-8 -*-
# @Author    :Timo

from __future__ import unicode_literals

from django.contrib.auth.models import AbstractUser
from django.db import models
from django.urls import reverse
from six import python_2_unicode_compatible


@python_2_unicode_compatible
class User(AbstractUser):
    """
    Default custom user model for zanhu.
    If adding fields that need to be filled at user signup,
    check forms.SignupForm and forms.SocialSignupForms accordingly.
    自定义用户模型
    """

    #: First and last name do not cover name patterns around the globe
    nickname = models.CharField(max_length=255, null=True, blank=True, verbose_name="昵称")
    job_title = models.CharField(max_length=50, null=True, blank=True, verbose_name="职称")
    introduction = models.TextField(null=True, blank=True, verbose_name="简介")
    picture = models.ImageField(upload_to="profile_pics", null=True, blank=True, verbose_name="头像")
    location = models.CharField(max_length=50, null=True, blank=True, verbose_name="城市")
    personal_url = models.URLField(max_length=255, null=True, blank=True, verbose_name="个人链接")
    weibo = models.URLField(max_length=255, null=True, blank=True, verbose_name="微博链接")
    zhihu = models.URLField(max_length=255, null=True, blank=True, verbose_name="知乎链接")
    github = models.URLField(max_length=255, null=True, blank=True, verbose_name="GitHub链接")
    linkedin = models.URLField(max_length=255, null=True, blank=True, verbose_name="LinkedIn链接")
    created_at = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    updated_at = models.DateTimeField(auto_now=True, verbose_name="更新时间")

    class Meta:
        verbose_name = "用户"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.username

    def get_absolute_url(self):
        """Get url for user's detail view.

        Returns:
            str: URL for user detail.

        """
        return reverse("users:detail", kwargs={"username": self.username})

    def get_profile_name(self):
        if self.nickname:
            return self.nickname
        return self.username
